package club.yunqiang.gui;

import javax.swing.*;
import java.awt.*;
import java.time.LocalDateTime;
import java.util.Random;
import java.util.concurrent.TimeUnit;

/**
 * @author 张云强
 * @date 2019/7/14
 */
public class HelloSwing {
    public static void main(String[] args) throws InterruptedException {
        JFrame jFrame = new JFrame();
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jFrame.setSize(300, 100);
        jFrame.setVisible(true);
        jFrame.getContentPane().setLayout(new FlowLayout());

        // 添加随机标签
        Random random = new Random();
        while (true){
            TimeUnit.SECONDS.sleep(1);
            SwingUtilities.invokeLater(() -> {
                JLabel jLabel = new JLabel("label-" + random.nextInt());
                jFrame.add(jLabel);
            });
        }
    }
}
